package com.obixlabs.security.credentialsstore.server.dao.ldapimpl;

import java.io.Serializable;

import javax.naming.NamingException;
import javax.naming.directory.DirContext;

import com.obixlabs.security.credentialsstore.server.dao.ldapimpl.config.LDAPConnectionInfo;

public class LDAPConnection implements Serializable
{
	private static final long serialVersionUID = -5733040407962868831L;
	

	private LDAPConnectionInfo connectionInfo;
	private String principalDN;
	private String credentials;

	private DirContext context;

	public LDAPConnection(	LDAPConnectionInfo connectionInfo, 
							String principal,
							String credentials) throws NamingException
	{
		this();
		setConnectionInfo(connectionInfo);
		setPrincipalDN(principal);
		setCredentials(credentials);		
		setContext(	LDAPContextFactory.createLDAPContext(	this.connectionInfo, 
															this.principalDN, 
															this.credentials)
					);
	}

	private LDAPConnection(){}

	public LDAPConnectionInfo getConnectionInfo(){return connectionInfo;}

	private void setConnectionInfo(LDAPConnectionInfo connectionInfo)
	{this.connectionInfo = connectionInfo;}

	public String getPrincipalDN(){return principalDN;}
	private void setPrincipalDN(String principal)
	{this.principalDN = principal;}

	public String getCredentials(){return credentials;}

	private void setCredentials(String credentials)
	{this.credentials = credentials;}

	public DirContext getContext(){return context;}

	private void setContext(DirContext context)
	{this.context = context;}
	
}